import Vue from 'vue'
import VueRouter from 'vue-router'
import 'element-ui/lib/theme-chalk/index.css'
import Home from '../views/Home.vue'
import Login from '../views/Login.vue'
import Index from '../views/Index.vue'
import Welcome from '../views/Welcome.vue'
import GoodsType from '../views/goods/goodsConfig/GoodsType.vue'
import AddGoods from '../views/goods/goodsConfig/AddGoods.vue'
import GoodsList from '../views/goods/goodsManage/GoodsList.vue'

Vue.use(VueRouter)

const router = new VueRouter({
  routes: [
    { path: '/', redirect: '/login' },
    { path: '/login', name: 'Login', component: Login },
    {
      path: '/home',
      component: Home,
      redirect: '/welcome',
      children: [
        { path: '/welcome', component: Welcome },
        { path: '/index', component: Index },
        { path: '/goods', redirect: '/goodslist' },
        { path: '/goodsType', component: GoodsType },
        { path: '/addGoods', component: AddGoods },
        { path: '/goodslist', component: GoodsList }
      ]
    }
  ]
})

// 给路由实例 添加导航守卫
// router.beforeEach((to, form, next) => {
//   if (to.path === '/login') return next()
//   let getToken = window.sessionStorage.getItem('token')
//   if (!getToken) {
//     router.push('/login')
//   }
//   next()
// })

export default router
